<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org" xmlns:cb="http://www.ossbar.com/">
<head th:include="layout/head" />
<div th:include="layout/foot"></div>
<script type="text/javascript" th:inline="javascript">
	cb.loadmodules([ "validate", "ajax", "lay" ]);
</script>
<script type="text/javascript" charset="utf-8"
		th:src="@{/plugins/ueditor/ueditor.config.js}"></script>
<script type="text/javascript" charset="utf-8"
	th:src="@{/plugins/ueditor/ueditor.all.js}"></script>
<script type="text/javascript"
	th:src="@{/plugins/ueditor/lang/zh-cn/zh-cn.js}"></script>
<body>
<form class="form-horizontal" id="tmailDetailForm" method="post" th:action="@{/mail/tmaildetail/sendEmail}" th:object="${tmailDetail}">
		<div class="panel-body">
			<!-- 按钮栏布局begin -->
			<div id="toolbar_area" class="toolbar_area" style="text-align:left">
				<a class="btn btn-default cb-btn" lay-filter="formDemo"
					href="javascript:void(0)" onclick="replay()"><i
					class="glyphicon glyphicon-plus"></i>&nbsp;回复</a>
			</div>
			<!-- 按钮栏布局end -->
		</div>
		<input type="hidden" name="tokenForm"
			th:value="${#session.getAttribute('tokenForm')}" />
		<input type="hidden" name="mid"
			th:value="*{mid}" />
		<table class="table table-bordered FormView cb-table-fun">
				<tr>
				<td class="cb-label" style="width: 100px">发件人：</td>
				<td class="cb-value" style="width: 95%" th:text="*{msender}"></td>
				</tr>
				<tr>
				<td class="cb-label" style="width: 100px">收件人：</td>
				<td class="cb-value" style="width: 95%" id="to"></td>
				</tr>
				<tr>
				<td class="cb-label" style="width: 100px">抄送人：</td>
				<td class="cb-value" id="cc"></td>
				</tr>
				<tr>
				<td class="cb-label" style="width: 100px">邮件主题：</td>
				<td class="cb-value" th:text="*{msubject}"></td>
				</tr>
				<tr>
				<td colspan="2" id="attachlist"></td>
				</tr>
				<tr>
				<td class="cb-value" colspan="2">
				<div id="mcontent" name="mcontent" style="width:100%;height:500px;"></div>
				</td>
				</tr>
		</table>
	</form>
</body>
<script type="text/javascript" th:inline="javascript">
	if([[${tmailDetail}]].attachList && [[${tmailDetail}]].attachList.length > 0){
		var list = [[${tmailDetail}]].attachList;
		for(var i=0; i<list.length; i++){
			$("#attachlist").append("<a download='"+list[i].maSecondName+"' href='"+list[i].maLj+"'>"+list[i].maSecondName+"</a>&nbsp;&nbsp;&nbsp;");
		}
	}
	if([[${tmailDetail}]].receiverList && [[${tmailDetail}]].receiverList.length > 0){
		var list = [[${tmailDetail}]].receiverList;
		var tos="",ccs="",bccs="";
		for(var i=0; i<list.length; i++){
			if("TO"==list[i].mrType){
				if(list[i].mrName){
					tos=","+list[i].mrName+"<"+list[i].mrMail+">" + tos;
				}else{
					tos=","+list[i].mrMail + tos;
				}
			}else if("CC"==list[i].mrType){
				if(list[i].mrName){
					ccs=","+list[i].mrName+"<"+list[i].mrMail+">" + ccs;
				}else{
					ccs=","+list[i].mrMail + ccs;
				}
			}else if("BCC"==list[i].mrType){
				if(list[i].mrName){
					bccs=","+list[i].mrName+"<"+list[i].mrMail+">" + bccs;
				}else{
					bccs=","+list[i].mrMail + bccs;
				}
			}
		}
		if(tos){
			$("#to").html(tos.substr(1));
		}
		if(ccs){
			$("#cc").html(ccs.substr(1));
		}
	}
	if(vcontent){
		vcontent.destroy();
	}
	var vcontent = UE.getEditor("mcontent",{
	    toolbars: [
	    	['undo', 'redo', '|',
	            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript',  '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'cleardoc', '|',
	            'customstyle', 'paragraph', 'fontfamily','fontsize','fullscreen','|','justifyleft', //居左对齐
	            'justifyright', //居右对齐
	            'justifycenter', //居中对齐
	            'justifyjustify',
	            'simpleupload', 'insertimage','insertvideo','attachment','snapscreen', 'emotion','fixedpic']
	    ],
	    autoHeightEnabled: true,
	    autoFloatEnabled: true,
	    pasteplain:true,
	    elementPathEnabled : false
	});
	var maSign = ([[${tmailDetail}]] && [[${tmailDetail.mcontent}]])?[[${tmailDetail.mcontent}]]:[[${maSign}]];
	if(maSign != null){
		vcontent.ready(function() {//编辑器初始化完成再赋值  
			vcontent.setContent(maSign);
			vcontent.setDisabled();
		});
	}
	//保存
	function save() {// save_click()

		cb.submit("#tmailDetailForm", "mail/tmaildetail/saveorupdate", function() {
			cb.alert("保存成功", function() {
				var mytab = parent.tab;
				mytab.deleteTab(mytab.getCurrentTabId());
			});
		}, {
			contentType : "application/x-www-form-urlencoded"
		})
	}
	//发送
	function send() {// save_click()

		cb.submit("#tmailDetailForm", "mail/tmaildetail/sendEmail", function() {
			cb.alert("发送成功", function() {
				var mytab = parent.tab;
				mytab.deleteTab(mytab.getCurrentTabId());
			});
		}, {
			contentType : "application/x-www-form-urlencoded"
		})
	}
	function replay() {
		var data={};
		data.title="回复邮件";
		data.icon="glyphicon glyphicon-eye-open";
		data.href=cb.baseurl + "mail/tmaildetail/replay/"+[[${tmailDetail}]].mid+"?token="+cb.token;
		parent.tab.tabAdd(data);
	}
</script>
</html>